<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px">
      <el-form-item label="工程编号" prop="projectId">
        <el-input
          v-model="queryParams.projectId"
          clearable
          placeholder="请输入工程编号"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleAgree"
        >同意</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          size="mini"
          type="success"
          icon="el-icon-edit"
          :disabled="single"
          @click="handleRefuse"
        >拒绝</el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="repairSignList" @selection-change="handleSelectionChange">
      <el-table-column align="center" type="selection" width="55"/>
      <el-table-column align="center" label="地址" prop="doorAddr" width="200"/>
      <el-table-column align="center" label="房屋编号" prop="houseId"/>
      <el-table-column label="签字图片" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
        <span style="color:#007aff" @click="openCard(scope.row.signPhotoHttp,scope.row.signPhotoName)">{{ scope.row.signPhotoName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="签字状态" align="center" prop="signSts">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.REPAIR005" :value="scope.row.signSts"/>
        </template>
      </el-table-column>
      <el-table-column align="center" label="面积" prop="space"/>
      <el-table-column align="center" label="预缴金额" prop="budgetMoney"/>S
      <el-table-column align="center" label="账户余额" prop="balance"/>
      <el-table-column align="center" label="分摊金额" prop="repairMoney"/>
      <el-table-column align="center" label="不足金额" prop="noMoney"/>
      <el-table-column align="center" label="拨付金额" prop="payMoney"/>
      <el-table-column align="center" label="分摊后余额" prop="afterBalance"/>
    </el-table>

    <pagination
      v-show="total>0"
      :limit.sync="queryParams.pageSize"
      :page.sync="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />

    <el-dialog :title="titleCard" :visible.sync="showCard" width="500px" append-to-body>
       <div style="text-align:center">
       <img style="width:400px" :src="cardUrl" />
       </div>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="showCard=false">关闭</el-button>
        </div>
      </el-dialog>

  </div>
</template>

<script>
import {listRepairSign, updateRepairSign} from "@/api/repair/repairSignature";

export default {
  name: "RepairSign",
  dicts: ['REPAIR005'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 户资金修改表格数据
      repairSignList: [],
      // 弹出层标题
      title: "",
      titleDetail: "",
      // 是否显示弹出层
      open: false,
      openDetail: false,
      // 查询参数
      queryParams: {
        projectId: null,
        projectSts:0,
        projectType:1,
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      cardUrl:'',
      titleCard:'',
      showCard:false,
      // 表单校验
      rules: {
        projectId: [
          {required: true, message: "工程编号不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询户资金修改列表 */
    openCard(id,name){
        this.titleCard = name
        console.log(id)
        this.cardUrl=id;
        this.showCard=true;
      },
    getList() {
      this.loading = true;
      listRepairSign(this.queryParams).then(response => {
        this.repairSignList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleAgree() {
      this.loading = true;
      updateRepairSign(this.queryParams.projectId,this.houseIds,"1").then(response => {
        this.getList();
      });
    },
    handleRefuse() {
      this.loading = true;
      updateRepairSign(this.queryParams.projectId,this.houseIds,"2").then(response => {
        this.getList();
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openDetail = false;
      this.reset();
      this.resetDetail();
    },
    // 表单重置
    reset() {
      this.form = {
        projectId: null,
        areaName: null,
        groupName: null,
        unitName: null,
        doorName: null,
        houseId: null,
        space: null,
        budgetMoney: null,
        repairMoney: null,
        noMoney:null,
        afterBalance: null,
        payMoney: null,
        balance: null
      };
    },
    resetDetail() {
          this.formDetail = {
            projectId: null,
            houseId: null,
            repairMoney: null,
            noMoney: null
          };
          this.resetForm("formDetail");
        },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.houseIds = selection.map(item => item.houseId)
      this.projectId = selection.map(item => item.projectId)
      this.single = !selection.length
      selection.map(item => {
        if(item.signSts!=0){
          this.single  = true;
        }
      })
    },

  }
};
</script>
